import 'package:animated_interpolation/smart_tabbar.dart';
import 'package:animated_interpolation/sweet_indicator_painter.dart';
import 'package:coinbaby/common/const/cosnt.dart';
import 'package:coinbaby/common/textstyle/textstyle.dart';
import 'package:flutter/material.dart';

class SelectTabView extends StatelessWidget {
  
  final TabController tabController;
  final List<String> titles;
  final int currentIndex;
  final Function(int index) onTap;
  final double horizontal;
  final double paddingTop;
  const SelectTabView({
    Key key, 
    this.tabController, 
    this.titles, 
    this.currentIndex, 
    this.onTap,
    this.horizontal = 80,
    this.paddingTop = 15
  }) : super(key: key);

  TextStyle normalStyle(int index) {
    return index == currentIndex ? AppFont.textStyle(18, AppColor.blue, fontWeight: FontWeight.bold) : AppFont.textStyle(15, AppColor.fontgrey);
  }

  @override
  Widget build(BuildContext context) {
    return Container(
      height: 44,
      padding: EdgeInsets.symmetric(horizontal: horizontal),
      margin: EdgeInsets.only(top: paddingTop),
      child: SmartTabBar(
        labelColor: AppColor.fontgrey,
        controller: tabController,
        indicatorColor: AppColor.blue,
        indicatorBuilder: (context,controller,indicator,indicatorSize,tabKeys,old)=>SweetIndicatorPainter(
          controller: controller,
          indicatorSize: indicatorSize,
          indicator: indicator,
          tabKeys: tabKeys,
          old: old
        ),
        tabs: titles.map((e) => Text(e, style: normalStyle(titles.indexOf(e)))).toList(),
        onTap: onTap,
      ),
    );
  }
}